from flask import Blueprint, jsonify, render_template

bp = Blueprint("admin", __name__, url_prefix="/admin")


@bp.get("/")
def index_get():
    return render_template("admin/index.html")


@bp.get("/menu")
def menu_get():
    data = [
        {
            "id": 1,  # 菜单数据的唯一标识
            "title": "首页",  # 界面中所显示的菜单标题
            "icon": "layui-icon layui-icon-console",  # 显示图标
            "type": 1,  # 0=目录, 1=菜单
            "href": "/admin",  # 菜单类型下访问的页面
        },
        {
            "id": 2,
            "title": "文章管理",
            "icon": "layui-icon layui-icon-list",
            "type": 0,
            "children": [
                {
                    "id": 21,
                    "title": "添加文章",
                    "icon": "layui-icon layui-icon-addition",
                    "type": 1,
                    "openType": "_iframe",  # 当 type 为 1 时，openType 生效，_iframe 正常打开 _blank 新建浏览器标签页
                    "href": "/admin/article/add",
                },
                {
                    "id": 22,
                    "title": "数据分析",
                    "icon": "layui-icon layui-icon-console",
                    "type": 1,
                    "openType": "_iframe",
                    "href": "/admin/article/analysis",
                },
            ],
        },
        {
            "id": 3,
            "title": "外部链接",
            "icon": "layui-icon layui-icon-chrome",
            "type": 1,
            "openType": "_blank",
            "href": "https://layui.dev",
        },
    ]
    return jsonify(data)


@bp.get("/message")
def message_get():
    data = {
        "code": 200,
        "data": [
            {
                "id": 1,
                "title": "通知",
                "children": [
                    {
                        "id": 11,
                        "avatar": "https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png",
                        "title": "你收到了 14 份新周报",
                        "context": "这是消息内容。",
                        "form": "就眠仪式",
                        "time": "刚刚",
                    }
                ],
            }
        ],
    }
    return jsonify(data)


@bp.get("/home")
def home_get():
    return "<h1>Home</h1>"


@bp.get("/article/add")
def article_add_get():
    return "<h1>添加文章</h1>"


@bp.get("/article/analysis")
def article_analysis_get():
    return "<h1>数据分析</h1>"
